package com.bondar.classloader;

import java.io.File;

public class Test {
	
	public static final String NAME = "com.bondar.classloader.TestModule";

	public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
		
		ClassLoader classLoader = new CustomCL();
		
		Class<?> loadClass = classLoader.loadClass(NAME);
		Object module = loadClass.newInstance();

		File fileJava = new File(NAME.replace('.', '/') + ".java");
		File fileClass = new File(NAME.replace('.', '/') + ".class");


		while (true) {
			
			if (fileJava.lastModified() > fileClass.lastModified()) {
				classLoader = new CustomCL();
				loadClass = classLoader.loadClass(NAME);
				module = loadClass.newInstance();
			}

			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}

			System.out.println(module.toString());
		}

	}

}
